import { StorageUtil } from './storage'

const TOKEN_KEY = 'auth_token'
const USER_INFO_KEY = 'user_info'

export const setToken = (token) => {
  StorageUtil.set(TOKEN_KEY, token)
}

export const getToken = () => {
  return StorageUtil.get(TOKEN_KEY)
}

export const removeToken = () => {
  StorageUtil.remove(TOKEN_KEY)
}

export const setUserInfo = (userInfo) => {
  StorageUtil.set(USER_INFO_KEY, userInfo)
}

export const getUserInfo = () => {
  return StorageUtil.get(USER_INFO_KEY)
}

export const removeUserInfo = () => {
  StorageUtil.remove(USER_INFO_KEY)
}

export const clearAuth = () => {
  removeToken()
  removeUserInfo()
}

export const isAuthenticated = () => {
  return !!getToken()
}